/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.client;
import cstAndEnum.JUDGE_TYPE;
import myTest.MYTest;
import models.Game;
import models.Player;

/**
 *
 * @author Invince
 */
public class Client_Public_Data {
/*----------Attributs-------------------*/
    /**----共享变量------------**/
    /**
     * 游戏所有的信息
     */
    public static Game gameInfoClient;
    public static final Object semaGameInfoClient=new Object();
    /**
     * 玩家
     */
    public static Player myInfo;
    public static final Object semaMyInfo=new Object();
    /**
     * 是否是自己的轮次
     */
    public static boolean isMyTurn;
    public static final Object semaIsMyTurn=new Object();
    /**
     * 保存判定阶段的判断结果（注意像八卦阵之类不算在这里）
     */
    public static JudgeResult judgeResult=new JudgeResult();
    public static final Object semaJudgeResult=new Object();
        public static class JudgeResult{
            /**
             * 乐不思蜀
             */
            protected boolean lbss;
            /**
             * 兵粮寸断
             */
            protected boolean blcd;
            /**
             * 闪电
             */
            protected boolean lightening;
            public JudgeResult() {
                this.blcd=false;
                this.lbss=false;
                this.lightening=false;
            }
            public boolean isBLCD() {return blcd;}
            public void setBLCD(boolean blcd) {this.blcd = blcd;}
            public boolean isLBSS() {return lbss;}
            public void setLBSS(boolean lbss) {this.lbss = lbss;}
            public boolean isLIGHTENING() {return lightening;}
            public void setLIGHTENING(boolean lightening) {this.lightening = lightening;}
            public void set(JUDGE_TYPE judgeType,boolean bool){
                if(judgeType.equals(JUDGE_TYPE.BLCD)){
                    setBLCD(bool);
                }else if(judgeType.equals(JUDGE_TYPE.LBSS)){
                    setLBSS(bool);
                }else if(judgeType.equals(JUDGE_TYPE.LIGHTENING)){
                    setLIGHTENING(bool);
                }
            }
        }

    /**
     * 剩余判定数，在myTurnBegin里刷新，msgHandler没接到一个JudgeResult自动--
     */
    public static int nbRestJudge;
    public static final Object semaNbRestJudge=new Object();
    /**
     * 出牌是否结束
     */
    public static boolean isCastOver;
    public static final Object semaIsCastOver=new Object();
    /**
     * 轮次结束
     */
     public static boolean isTurnOver;
     public static final Object semaIsTurnOver=new Object();
     /**
     * 是否出过杀
     */
    public static boolean isShaCasted;
    public static final Object semaIsShaCasted=new Object();




/*----------Public functions------------*/
        /**
         * 轮次开始时用
         * 在T_Client_Judge_Phase初，myTurnBegin()
         */
        public static void myTurnBegin(){
            int restJudge;
            synchronized(Client_Public_Data.semaMyInfo){
                restJudge=Client_Public_Data.myInfo.getDeckBuff().size();
            }
            synchronized(Client_Public_Data.semaNbRestJudge){//刷新该轮此nbRestJudge的数量
                Client_Public_Data.nbRestJudge=restJudge;
            }
            synchronized(Client_Public_Data.semaIsShaCasted){//重置是否出了杀
                 Client_Public_Data.isShaCasted=false;
            }
            synchronized(Client_Public_Data.semaIsMyTurn){
                Client_Public_Data.isMyTurn=true;
            }
            synchronized(Client_Public_Data.semaIsTurnOver){
                Client_Public_Data.isTurnOver=false;
            }
            synchronized(Client_Public_Data.semaJudgeResult){
                Client_Public_Data.judgeResult=new Client_Public_Data.JudgeResult();
            }
            MYTest.println("Player "+Client_Public_Data.myInfo.getName()+"'s Turn begins.");
        }

        /**
         * 结束轮次时用
         * 在T_Client_Drop_Phase最后用
         */
        public static synchronized void myTurnEnd(){
            synchronized(Client_Public_Data.semaIsMyTurn){
                Client_Public_Data.isMyTurn=false;
            }
            MYTest.println("Player "+Client_Public_Data.myInfo.getName()+"'s Turn ends.");
        }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
/*----------Gets and sets---------------*/
}
